#ifndef IRcommunication_h
#define IRcommunication_h

#define disableFlagExtInt1() ( EIFR |= (1 << INTF1 ) )

/****
 * TO WIKI
 * this class has a protocol for comunicating two arduinos
 * the protocol can be overriden and set to other defaults
 * to comunicate with other devices
 * there are also librearies to temporary comunicate with other devices without defining a protocol
 */

class IRcommunication {

public:
  void begin(uint8_t pinEmmiter, uint8_t pinReceiver);

  volatile uint8_t irLed;
  volatile uint8_t irReceiver;

  void send(unsigned int message);
  int receive();

  //Frequency Signal Generation (38 kHz)
  static const uint8_t halfPeriod = 1;
  static const uint8_t period = 2;

  //the following consts should be overwritten by the child class
  //all medium methods and properties are protected. Only a child should be able to change those
  //classes only using the IRcommunication to communicate should not know nothing about the medium
  //Frequency Signal Generation (38 kHz)

  //DEFAULT PROTOCOL
  static const unsigned int minHeaderDuration = 4300; //2400 us
  static const unsigned int headerDuration = 4800; //2400 us
  static const unsigned int maxHeaderDuration = 5300; //2400 us

  static const unsigned int minOneDuration = 1900; //1200 us
  static const unsigned int oneDuration = 2400; //1200 us
  static const unsigned int maxOneDuration = 2900; //1200 us

  static const unsigned int minZeroDuration = 700; //600 us
  static const unsigned int zeroDuration = 1200; //600 us
  static const unsigned int maxZeroDuration = 1700; //600 us

  static const unsigned int minDelayDuration = 700; //600 us
  static const unsigned int delayDuration = 1200; //600 us
  static const unsigned int maxDelayDuration = 1700; //600 us


  void sendBit(bool bit);
  void sendPulse(unsigned int duration);
  void sendDelay();
};


#endif

